package com.yjy.fuyao.ucenter.service.impl;


import com.yjy.fuyao.ucenter.client.MailClient;
import com.yjy.fuyao.ucenter.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

@Service
public class MailServiceImpl implements MailService {

    @Autowired
    private MailClient mailClient;

    @Autowired
    private TemplateEngine templateEngine;

    public boolean send(String mail,String code){
        System.out.println("==========send:进来了==============");
        Context context = new Context();
        context.setVariable("code",code);
        String content = templateEngine.process("/mail/active", context);
        try {
            mailClient.sendMail(mail,"扶摇学院，账号注册",content);
        } catch (Exception e) {
            System.out.println("fail:\n"+e);
            return false;
        }
        return true;
    }

}
